﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GuiAndDb
{
    public partial class Stock : Form
    {
        public Stock()
        {
            InitializeComponent();
            dataGridView1.AutoGenerateColumns = false;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            RefreshData();
        }

        private void RefreshData()
        {
            ProductDB pdp = new ProductDB();
            dataGridView1.DataSource = pdp.GetPatients();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ProductDetailsForm f2 = new ProductDetailsForm();
            if (f2.ShowDialog() == DialogResult.OK)
            {
                Product p = f2.Product;
                ProductDB pdp = new ProductDB();
                pdp.Add(p);

                RefreshData();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ProductDetailsForm f2 = new ProductDetailsForm();
            Product p = (Product)dataGridView1.CurrentRow.DataBoundItem;

            f2.Product = p;
            if (f2.ShowDialog() == DialogResult.OK)
            {
                ProductDB pdp = new ProductDB();
                pdp.Update(p);

                RefreshData();
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Do you want to delete patient?", "delete", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                Product p = (Product)dataGridView1.CurrentRow.DataBoundItem;
                ProductDB pdp = new ProductDB();
                pdp.Delete(p);

                RefreshData();
            }
        }
    }
}
